<?php declare(strict_types=1);

namespace App\Api\V2\Controller\Merchant;


use App\Api\Controllers\BaseController;
use App\Traits\ResponseTrait;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class MerchantController extends BaseController
{

    use ResponseTrait;

    //所有系统通道已经开通的-new
    public function store_open_pay_way_lists(Request $request)
    {
        try {
            $user = $this->parseToken();
            $store_id = $request->get('store_id', '');
            if (!empty($store_id)) {
                $data = DB::table('store_all_pay_way_lists')
                    ->join('store_pay_ways', 'store_all_pay_way_lists.company', '=', 'store_pay_ways.company')
                    ->where('store_pay_ways.store_id', $store_id)
                    ->where('store_pay_ways.status', 1)
                    ->select('store_all_pay_way_lists.company', 'store_all_pay_way_lists.company_desc')
                    ->distinct()
                    ->get();
            } else {
                $data = DB::table('store_all_pay_way_lists')
                    ->get();
            }
            return $this->successResponse("ok", ["data" => $data]);
        } catch (\Exception $exception) {
            return $this->errorResponse($exception->getMessage() . ' - ' . $exception->getLine());
        }
    }
}